googlemapsfield.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 9.4285
1
const targets = Array.from(document.body.querySelectorAll('input[data-mapsfield=mapsfield]'));
2
const latField = document.getElementById('GoogleMapsLatField');
3
const lngField = document.getElementById('GoogleMapsLngField');
4
5
let options = {};
6
let autoComplete;
7
8
const fillAddress = () => {
9
  const event = new Event('change');
0 ignored issues
show
Bug introduced by
The variable Event seems to be never declared. If this is a global, consider adding a /** global: Event */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
  const location = autoComplete.getPlace();
11
  const components = location.address_components;
12
13
  latField.setAttribute('value', location.geometry.location.lat());
14
  lngField.setAttribute('value', location.geometry.location.lng());
15
16
  components.forEach((component) => {
17
    component.types.forEach((type) => {
18
      const field = document.getElementById(type);
19
      if (field) {
20
        field.setAttribute('value', component.long_name);
21
        field.dispatchEvent(event);
22
      }
23
    });
24
  });
25
};
26
27
const mountMapsField = (mapsfield) => {
28
  options = Object.assign(options, window.customisations);
29
  autoComplete = new google.maps.places.Autocomplete(mapsfield, options);
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
30
  autoComplete.addListener('place_changed', fillAddress);
31
};
32
33
export default function() {
34
  targets.forEach(mountMapsField);
35
}